<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>排序稳定</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="bootstrap/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
    <link href="css/colors.min.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="bootstrap/js/html5shiv.min.js"></script>
    <script src="bootstrap/js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<h1>使用<code>sortStable</code>选项获得稳定的排序。</h1>
<div class="toolbar">
    <label>
        <input type="checkbox" id="sortStable" checked /> sortStable
    </label>
</div>

<table id="table"
       data-height="400"
       data-toolbar=".toolbar">
    <thead>
    <tr>
        <th data-field="id">Item ID</th>
        <th data-field="name" data-sortable="true">Item Name</th>
        <th data-field="price">Item Price</th>
    </tr>
    </thead>
</table>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="bootstrap/js/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="bootstrap/js/bootstrap-table.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="bootstrap/js/bootstrap-table-zh-CN.min.js"></script>
<script>
    var data = [
        {
            id: 0,
            name: 'test0',
            price: '$0'
        },
        {
            id: 1,
            name: 'test0',
            price: '$1'
        },
        {
            id: 2,
            name: 'test0',
            price: '$2'
        },
        {
            id: 3,
            name: 'test0',
            price: '$3'
        },
        {
            id: 4,
            name: 'test0',
            price: '$4'
        },
        {
            id: 5,
            name: 'test0',
            price: '$5'
        },
        {
            id: 6,
            name: 'test0',
            price: '$6'
        },
        {
            id: 7,
            name: 'test0',
            price: '$7'
        },
        {
            id: 8,
            name: 'test0',
            price: '$8'
        },
        {
            id: 9,
            name: 'test0',
            price: '$9'
        },
        {
            id: 10,
            name: 'test0',
            price: '$10'
        },
        {
            id: 11,
            name: 'test0',
            price: '$11'
        },
        {
            id: 12,
            name: 'test0',
            price: '$12'
        },
        {
            id: 13,
            name: 'test0',
            price: '$13'
        },
        {
            id: 14,
            name: 'test0',
            price: '$14'
        },
        {
            id: 15,
            name: 'test0',
            price: '$15'
        },
        {
            id: 16,
            name: 'test0',
            price: '$16'
        },
        {
            id: 17,
            name: 'test0',
            price: '$17'
        },
        {
            id: 18,
            name: 'test0',
            price: '$18'
        },
        {
            id: 19,
            name: 'test0',
            price: '$19'
        },
        {
            id: 20,
            name: 'test0',
            price: '$20'
        }
    ]

    var $table = $('#table')

    $(function() {
        $table.bootstrapTable({
            data: data,
            sortStable: true
        })

        $('#sortStable').change(function () {
            $table.bootstrapTable('refreshOptions', {
                sortStable: $('#sortStable').prop('checked')
            })
        })
    })

</script>
</body>
</html>